package logic

import (
	"bw-renting/model/mysql"
	"context"
	"encoding/json"

	"bw-renting/order-rpc/internal/svc"
	"bw-renting/order-rpc/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetOrderInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetOrderInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderInfoLogic {
	return &GetOrderInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 获取订单信息
func (l *GetOrderInfoLogic) GetOrderInfo(in *order.GetOrderInfoReq) (*order.GetOrderInfoRes, error) {
	// todo: add your logic here and delete this line
	orders := mysql.GetOrderInfo(in.OrderId)
	if orders.ID == 0 {
		return &order.GetOrderInfoRes{
			Data: "0",
		}, nil
	}
	res, _ := json.Marshal(orders)
	return &order.GetOrderInfoRes{
		Data: string(res),
	}, nil
}
